package adfc2.tasks;

import adfc2.actions.EnterWorkshopAction;
import adfc2.core.Action;
import adfc2.core.Creature;
import adfc2.core.Task;
import adfc2.entities.Workshop;

public class EnterWorkshopTask extends Task {

    public final Workshop target;

    public EnterWorkshopTask(Creature actor, Workshop target) {
        super(actor);
        this.target = target;
    }

    private MoveTask moving;

    @Override
    public Action nextAction() {
        if (actor.container == target) {
            completed();
            return null;
        } else if (actor.getXY() == target.getEntranceXY()) {
            return new EnterWorkshopAction(actor, target);
        } else {
            if (moving == null) {
                moving = new MoveTask(actor, target.getEntranceXY(), false);
            }
            return moving.nextAction();
        }
    }

    @Override
    public String toString() {
        return "EnterWorkshopTask[" + target.shortName() + "@" + target.getX() + "," + target.getY() + "]";
    }

    @Override
    public String shortName() {
        return "enter " + target.shortName();
    }
}
